using UnityEngine;
using System.Collections;
using System.Collections.Generic;
 



[System.Serializable]
public class CharacterKeyFrame : MonoBehaviour
{
	public int start = 0;
	public int end = 1;
	public bool always;
	public bool duration;

	[HideInInspector] public CharacterAnimatedState state;
	[HideInInspector] public List<CharacterAction> actions;

	public static int Compare(CharacterKeyFrame a, CharacterKeyFrame b)
	{
		return a.start.CompareTo(b.start);
	}

	public virtual void Init(CharacterAnimatedState state)
	{
		this.state = state;
		//seems not right here, please check it out,make a 
		actions = new List<CharacterAction>(GetComponentsInChildren<CharacterAction>());
        for(int i=0;i<actions.Count;i++)
        {
            actions[i].Init(this);
        }
		//action.AddRange(GetComponents<BaseFrameAction>()); 

		if(always)
		{
			start = 0; 
			end = -1;
		}
		else if(duration == false)
		{
			end = start + 1;
		}
	}

	public void DisplayFrame()
	{
		if(always)
		{
			gameObject.name = "Always";
		}
		else if(duration == false)
		{
			gameObject.name = "Frame" + start;
		}
		else 
		{
			gameObject.name = "Frame" + start + "To" + end;
		}
	}

	public void EnterFrame()
	{
		foreach(CharacterAction act in actions)
		{
			act.OnActionEnter(state.character); 
		}
	}
	
	public void ExitFrame()
	{
        for(int i=0;i<actions.Count;i++)
        {
            actions[i].OnActionExit(state.character);
        }
	}
}

